package com.smfx.yxt.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smfx.yxt.common.enums.ResourceType;
import com.smfx.yxt.daoSqlserver.SysResourceMapper;
import com.smfx.yxt.model.SysResource;
import com.smfx.yxt.page.Page;
import com.smfx.yxt.service.ISysResourceService;

@Service("sysResourceService")
public class SysResourceServiceImpl implements ISysResourceService {

	@Autowired
	private SysResourceMapper sysResourceMapper;
	@Override
	public List<SysResource> selectMenuByIds(String ids) {
		return sysResourceMapper.selectMenuByIds(ids);
	}

	@Override
	public List<SysResource> selectPageByIds(String ids) {
		return sysResourceMapper.selectPageByIds(ids);
	}

	@Override
	public List<SysResource> selectByPage(Page<SysResource> page) {
		return sysResourceMapper.selectByPage(page);
	}

	@Override
	public int addAndUpdateSysResource(SysResource record) {
		if(record.getId() == null) {
			if(StringUtils.isBlank(record.getIds()) && 
					!record.getResourceType().equals(ResourceType.MENU.getCode())) {
				record.setIds("0");
			}
			return sysResourceMapper.insertSelective(record);
		}
		if(StringUtils.isBlank(record.getIds())) {
			record.setIds("0");
		}
		return sysResourceMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int updateBatchDel(List<Integer> ids) {
		return sysResourceMapper.updateBatchDel(ids);
	}

	@Override
	public List<SysResource> selectByParam(SysResource record) {
		return sysResourceMapper.selectByParam(record);
	}


}
